package cn.iocoder.yudao.module.game.service.gameOverview;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.game.controller.admin.gameOverview.vo.*;
import cn.iocoder.yudao.module.game.dal.dataobject.gameOverview.GameOverviewDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.game.dal.mysql.gameOverview.GameOverviewMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.game.enums.ErrorCodeConstants.*;

/**
 * 游戏概况 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class GameOverviewServiceImpl implements GameOverviewService {

    @Resource
    private GameOverviewMapper overviewMapper;

    @Override
    public Long createOverview(GameOverviewSaveReqVO createReqVO) {
        // 插入
        GameOverviewDO overview = BeanUtils.toBean(createReqVO, GameOverviewDO.class);
        overviewMapper.insert(overview);
        // 返回
        return overview.getId();
    }

    @Override
    public void updateOverview(GameOverviewSaveReqVO updateReqVO) {
        // 校验存在
        validateOverviewExists(updateReqVO.getId());
        // 更新
        GameOverviewDO updateObj = BeanUtils.toBean(updateReqVO, GameOverviewDO.class);
        overviewMapper.updateById(updateObj);
    }

    @Override
    public void deleteOverview(Long id) {
        // 校验存在
        validateOverviewExists(id);
        // 删除
        overviewMapper.deleteById(id);
    }

    private void validateOverviewExists(Long id) {
        if (overviewMapper.selectById(id) == null) {
            throw exception(OVERVIEW_NOT_EXISTS);
        }
    }

    @Override
    public GameOverviewDO getOverview(Long id) {
        return overviewMapper.selectById(id);
    }

    @Override
    public PageResult<GameOverviewDO> getOverviewPage(GameOverviewPageReqVO pageReqVO) {
        return overviewMapper.selectPage(pageReqVO);
    }

}